package com.ayou.plugin;

import com.google.common.collect.Lists;

import java.util.Collections;
import java.util.List;

/**
 * @description: 插件责任链
 * @author: ayouman
 * @date: 2024/12/28 23:19
 */
public class InterptorChain {
    private List<Interceptor> interceptors = Lists.newArrayList();

    public void addInterceptor(Interceptor interceptor)
    {
        interceptors.add(interceptor);
    }

    public Object pluginAll(Object target)
    {
        for (Interceptor interceptor : interceptors) {
            target = interceptor.plugin(target);
        }
        return target;
    }

    public List<Interceptor> getInterceptors()
    {
        return Collections.unmodifiableList(interceptors);
    }
}
